import {
	uploadUrl
} from '@/pages/api/report/helperOrderp.js'
import {
	getByOrdersId,
	updatechutu,
	updatexiaona
} from '@/pages/api/report/orderp.js'
import {
	getOrderDetail,
	getWorkOrderLogs,
	getTakeTask,
	postOrderHandle,
	orgByNodeId,
	allocate,
	allocatedo,
	getPdf,
	detailById,
	postWithdraw,
	postOrderAudit,
	getTransferDepartment,
	getNextPersons,
	postOrderDispatch,
	postCheck,
	getMyList,
	postCloseOrder,
	postBackStep,
	cancelTask,
	allocatepostWithdraw,
	allocatepostCloseOrder,
	allocatepostBackStep
} from '@/pages/api/orderp/orderp.js'
import {
	addwgxnd,
	addwgczxx,
	addwgaj,
	addBeUnearthedField,
	upAbsorbPic
} from '@/pages/api/report/orderp.js'
// import { getaddEvent } from '@/api/wisdomEmergency/wisdom.js'
// import { getUrbanType } from '@/api/orderp/cityManagement/api.js'
import {
	mapState,
	mapMutations
} from 'vuex'
export default {
	computed: {
		...mapState(['userInfo', 'path']),
		inputed() {
			if (this.xiaonaEdit == 1) {
				return false
			} else {
				return true
			}
		}
	},
	methods: {
		...mapMutations('mdOrder', ['setOrderIdSp', 'setInfoOrder', 'setInfoRecords']),
		...mapMutations('mdApprove', ['setInfoApprove', 'setLicenseData']),
		// 选择部门弹窗
		choseDep() {
			this.departmentShow = true
		},
		// 更新部门
		updateDep(val) {
			this.departmentList.forEach((item, index) => {
				if (index == val) {
					this.detailmsg.competentDepartment = item.name
				}
			})
			console.log(this.detailmsg.competentDepartment)
		},
		//转发
		forward() {
			this.personShow = true
		},
		// 工单转发成功
		appointTaskSuccess() {
			uni.$emit('updatelist', 10)
			this.$refs.uToast.show({
				title: '转发成功',
				type: 'success',
				url: '/pages/index/approval/index'
			}, 500)
		},
		appointTaskCancel() {
			this.personShow = false
		},
		changesw(e) {
			console.log(e)
			this.tabCurrent = e.detail.current
		},
		//上传照片
		requestUploadImg(filePath, type) {
			console.log(filePath)
			return new Promise((resolve, reject) => {
				uni.uploadFile({
					url: uploadUrl,
					filePath,
					name: 'file',
					formData: {
						itemId: 'chengguansuishoupai'
					},
					success: (uploadFileRes) => {
						console.log('照片类型', type, JSON.parse(uploadFileRes.data).data.fileUrl)
						let arr = [JSON.parse(uploadFileRes.data).data.fileUrl]
						if (type == 1) {
							console.log('照片传值', this.detailmsg.plan, arr)
							// this.form.chukou.push(JSON.parse(uploadFileRes.data).data.fileUrl)
							this.detailmsg.plan = this.detailmsg.plan.concat(arr)
							console.log('照片传值', this.detailmsg.plan)
						}

					},
					fail: err => {
						console.log(err)
					}
				});
			})
		},
		fileTabChoose(type) {
			uni.chooseImage({
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['camera', 'album'], //从相册选择
				success: res => {
					console.log(res.tempFilePaths)
					res.tempFilePaths.forEach(e => {
						this.requestUploadImg(e, type)
					})
				}
			});
		},
		tabChange(index) {
			this.tabCurrent = index

		},
		//分派关闭工单
		allocateout() {
			if (this.outorder != 0) {
				uni.showModal({
					title: '提示',
					content: '是否确定提交？',
					confirmText: '确定',
					cancelText: '取消',
					success: res => {
						if (res.confirm) {
							if (this.outorder == 1) {
								allocatepostCloseOrder({
									id: this.id,
									other: {
										result: "关闭",
										content: this.type_value
									}
								}).then(d => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: '关闭成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 500)
								})
							} else if (this.outorder == 2) {
								allocatepostWithdraw({
									id: this.id,
									other: {
										result: "退单整改",
										content: this.type_value
									}
								}).then(res => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: '退单成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 500)
									// uni.navigateBack()
								})
							} else {
								allocatepostBackStep({
									id: this.id,
									other: {
										result: "返回上一节点",
										content: this.type_value
									}
								}).then(res => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: '返回上一节点成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 500)
								})
							}

						}
					}
				});
			}
		},
		//取消认领
		canceltake() {
			uni.showModal({
				title: '提示',
				content: '是否确定取消认领？',
				confirmText: '确定',
				cancelText: '取消',
				success: res => {
					if (res.confirm) {
						cancelTask({
							id: this.id
						}).then(res => {
							this.orderType = 0
							this.xiaonaEdit = -1
							this.xiaonaEdit2 = (this.stepsnumber == 3 ? -1 : null) //渣土办审核取消认领
						}).catch(res => {
							console.log(res)
							console.log(res.data.msg)
							uni.$emit('updatelist', 10)
							this.$refs.uToast.show({
								title: res.data.msg,
								type: 'warning',
								url: '/pages/index/approval/index'
							}, 300)
						})
					}
				}
			})
		},
		//更新申报表 -- 矿坑
		updatechutumsg() {
			let params = {
				id: this.detailmsg.id,
				plan: this.detailmsg.plan.join(',')
			}
			console.log(params)
			upAbsorbPic(params).then(res => {
				console.log('矿坑提交成回调', res)

			}).catch(e => {
				console.log(e)
			})


		},
		//更新申报表 --消纳
		updatexiaonamsg() {
			console.log(this.form, 'this.formformformformformform')
			let params = {
				excavatedMouthRoadSclerosis: this.form.chukou.join(','),
				flushingEquipment: this.form.chongxi.join(','),
				dustControl: this.form.fangchen.join(','),
				// videoSurveillance: this.form.shipin.join(','),
				other: this.form.qita.join(','),
				loessEarthQuantity: this.detailmsg.loessEarthQuantity1 + ',' + this.detailmsg.loessEarthQuantity2,
				plantingSoilEarthQuantity: this.detailmsg.plantingSoilEarthQuantity1 + ',' + this.detailmsg
					.plantingSoilEarthQuantity2,
				muckEarthQuantity: this.detailmsg.muckEarthQuantity1 + ',' + this.detailmsg.muckEarthQuantity2,
				slurryEarthQuantity: this.detailmsg.slurryEarthQuantity1 + ',' + this.detailmsg
					.slurryEarthQuantity2,
				wasterEarthQuantity: this.detailmsg.wasterEarthQuantity1 + ',' + this.detailmsg
					.wasterEarthQuantity2,
				dangEarthQuantity: this.detailmsg.dangEarthQuantity1 + ',' + this.detailmsg
					.dangEarthQuantity2,
				otherEarthQuantity: this.detailmsg.otherEarthQuantity1 + ',' + this.detailmsg.otherEarthQuantity2,
				allEarthQuantity: this.detailmsg.allEarthQuantity1 + ',' + this.detailmsg.allEarthQuantity2,
				competentDepartment: this.detailmsg.competentDepartment,
				useStartTime: this.time,
				useEndTime: this.time1,
				id: this.detailmsg.id,
				limits: this.$store.state.path.toString(),
				limitsCentre: this.$store.state.center.toString(),
				limitsArea: this.$store.state.polygonArea,
				fieldName: this.detailmsg.fieldName
			}
			console.log('消纳范围参数：',params)
			updatexiaona(params).then(res => {
				console.log(res, '更新成功。。。。。。。。。。')
				this.$refs.uToast.show({
					title: '提交成功',
					type: 'success'
				}, 300)
			}).catch(e => {
				console.log(e, '更新失败。。。。。。。。。。。。。。。。。。。。。。。。。')
			})
		},
		//通过审核
		approved() {
			if (this.buttontype == 1) {
				if (this.$store.state.path == 1) {
					this.$toast('请选择四至范围')
					return;
				}
				if (this.redshow1 && this.redshow2 && this.redshow3 && this.redshow4 && this.redshow5 && this
					.redshow6 && this.redshow7) {
					this.$toast('请填写正确的出土量')
					return;
				}
			}
			this.showPass = true
		},
		onSure() {
			console.log(this.buttontype)
			switch (this.buttontype) {
				case '1':
					this.passin()
					break;
				case '3':
					this.comfirm(true)
					break;
				case '11':
					this.comfirm_part()
					break;
				default:
			}
		},
		//通过审核跳转
		passin() {
			// console.log(this.checkop, 77777)
			if (this.stepsnumber != 1) { // 非现场踏勘
				// console.log("审核跳转" + this.checkop, 77777)
				uni.showModal({
					title: '提示',
					content: '是否确定提交审核？',
					confirmText: '确定',
					cancelText: '取消',
					success: res => {
						if (res.confirm) {
							postCheck({
								id: this.id,
								other: {
									result: "工单核验",
									content: this.pass_value
								}
							}).then(res => {
								this.show = false
								this.showPass = false
								this.$refs.uToast.show({
									title: '审核成功',
									type: 'success'
								}, 300)
								uni.$emit('updatelist', 10)
								// uni.navigateTo({
								// 	url: '/pages/index/approval/chutu/passin'
								// })
								uni.navigateTo({
									url: '/pages/index/approval/index'
								})
								console.log(res)
							}).catch(res => {
								console.log(res)
								console.log(res.data.msg)
								uni.$emit('updatelist', 10)
								this.$refs.uToast.show({
									title: res.data.msg,
									type: 'warning',
									url: '/pages/index/approval/index'
								}, 300)
							})
						}
					}
				});
			} else {
				uni.showModal({
					title: '提示',
					content: '是否确定提交审核？',
					confirmText: '确定',
					cancelText: '取消',
					success: res => {
						if (res.confirm) {
							postCheck({
								id: this.id,
								other: {
									result: "工单核验",
									content: this.pass_value
								}
							}).then(res => {
								this.show = false
								this.showPass = false
								this.buttontype = 10
								this.updatexiaonamsg()
								setTimeout(() => {
									let params = {
										// isDelay: this.isDelay,
										size: 1000,
										itemId: "402887ae7af5e872017af60b5a6f04a6"
									}
									getMyList(params).then(res => {
										res.rows.forEach(d => {
											if (d.id == this.idd) {
												this.id = d.recordId
												this.nodeId = d
													.nodeId
												this.getolddetail() //刷新整条工单
												this.xiaonaEdit = -
													1 // 不可编辑
											}
										})
									})
								}, 300)
				
							}).catch(res => {
								console.log(res)
								console.log(res.data.msg)
								uni.$emit('updatelist', 10)
								this.$refs.uToast.show({
									title: res.data.msg,
									type: 'warning',
									url: '/pages/index/approval/index'
								}, 300)
							})
						}
					}
				});
			}

		},
		// 选中某个单选框时，由radio时触发
		radioChange(e) {
			console.log(e);
		},
		// 选中任一radio时，由radio-group触发
		radioGroupChange(e) {

			// this.value[e] =  this.value[e]

			console.log(this.value);
		},
		//获取分配部门
		getorgByNodeId() {
			this.list = []
			orgByNodeId({
				nodeId: this.nodeId
			}).then(res => {
				// debugger
				// console.log(res, '----------------res')
				res.forEach(d => {
					this.list.push({
						nodeId: d.nodeId,
						orgId: d.orgId,
						orgName: d.orgName,
						checked: false,
						disabled: false
					})
				})
				this.list.forEach((item,index)=>{
					// 去除括号及内容
					item.orgName = item.orgName.replace(/\（.*?\）/g,'')  
				})
				// 默认选中字段
				this.list.forEach((item, index) => {
					if (this.detailmsg.competentDepartment == item.orgName) {
						item.checked = true
					} else if (this.detailmsg.street == item.orgName) {
						item.checked = true
					}
				})
				this.list.forEach((item, index) => {
					if(item.checked == true) {
						this.activelist.push(item.orgId)
						this.activeOrgName.push(item.orgName)
					}
				})
				console.log(res, 9999999, this.nodeId)
				console.log(res, 9999999, this.list)
			})
		},
		//更新图片地址
		updateUrlList(list, type) {
			console.log('list', list, type)
			// let formList = ['chukou', 'chongxi', 'fangchen', 'shipin', 'qita']
			let formList = ['chukou', 'chongxi', 'fangchen', 'qita']
			this.form[formList[type]] = list
			console.log(this.form)
		},
		getolddetail() {
			return new Promise((resolve, reject) => {
				getByOrdersId({
					ordersId: this.idd
				}).then(res => {
					let str = '350821 1998041349 17'
					console.log(res, 333)
					this.detailmsg = res
					this.setInfoApprove(res)
					if (res) {
						//身份证打码
						this.detailmsg.identityCard = this.detailmsg.identityCard.slice(0, 6) +
							'**********' + this.detailmsg.identityCard.slice(16, 18)


						this.detailmsg.loessEarthQuantity1 = this.detailmsg.loessEarthQuantity.split(
							',')[0]
						this.detailmsg.loessEarthQuantity2 = this.detailmsg.loessEarthQuantity.split(
							',')[1]
						this.detailmsg.plantingSoilEarthQuantity1 = this.detailmsg
							.plantingSoilEarthQuantity.split(',')[0]
						this.detailmsg.plantingSoilEarthQuantity2 = this.detailmsg
							.plantingSoilEarthQuantity.split(',')[1]
						this.detailmsg.muckEarthQuantity1 = this.detailmsg.muckEarthQuantity.split(',')[
							0]
						this.detailmsg.muckEarthQuantity2 = this.detailmsg.muckEarthQuantity.split(',')[
							1]
						this.detailmsg.slurryEarthQuantity1 = this.detailmsg.slurryEarthQuantity.split(
							',')[0]
						this.detailmsg.slurryEarthQuantity2 = this.detailmsg.slurryEarthQuantity.split(
							',')[1]
						this.detailmsg.wasterEarthQuantity1 = this.detailmsg.wasterEarthQuantity.split(
							',')[0]
						this.detailmsg.wasterEarthQuantity2 = this.detailmsg.wasterEarthQuantity.split(
							',')[1]
						this.detailmsg.otherEarthQuantity1 = this.detailmsg.otherEarthQuantity.split(
							',')[0]
						this.detailmsg.otherEarthQuantity2 = this.detailmsg.otherEarthQuantity.split(
							',')[1]
						this.detailmsg.allEarthQuantity1 = this.detailmsg.allEarthQuantity.split(',')[0]
						this.detailmsg.allEarthQuantity2 = this.detailmsg.allEarthQuantity.split(',')[1]
						this.detailmsg.dangEarthQuantity1 = this.detailmsg.dangEarthQuantity.split(',')[
							0]
						this.detailmsg.dangEarthQuantity2 = this.detailmsg.dangEarthQuantity.split(',')[
							1]
						this.time = this.detailmsg.useStartTime
						this.time1 = this.detailmsg.useEndTime
						console.log(this.detailmsg.accessRoadSclerosis)

						// if(this.detailmsg.accommodationFieldApplication==null || this.detailmsg.accommodationFieldApplication==''){
						// 	this.detailmsg.accommodationFieldApplication = []
						// }else{
						// 	this.detailmsg.accommodationFieldApplication = this.detailmsg.accommodationFieldApplication.split(',')
						// }

						//方案
						if (this.detailmsg.plan == null || this.detailmsg.plan == '') {
							this.detailmsg.plan = []
						} else {
							this.detailmsg.plan = this.detailmsg.plan.split(',')
						}
						// this.detailmsg.accommodationFieldApplication = this.detailmsg.accommodationFieldApplication.split(
						// ',')
						console.log(this.detailmsg.accommodationFieldApplication)

						// this.detailmsg.accommodationFieldApplication = this.detailmsg
						// 	.accommodationFieldApplication.split(',') || ''
						//出口道路硬化
						if (this.detailmsg.excavatedMouthRoadSclerosis == null || this.detailmsg
							.excavatedMouthRoadSclerosis == '') {
							this.detailmsg.excavatedMouthRoadSclerosis = []
							this.form.chukou = []
						} else {
							this.form.chukou = this.detailmsg.excavatedMouthRoadSclerosis.split(',')
							this.detailmsg.excavatedMouthRoadSclerosis = this.detailmsg
								.excavatedMouthRoadSclerosis
								.split(',')
						}
						//冲洗设备
						if (this.detailmsg.flushingEquipment == null || this.detailmsg
							.flushingEquipment == '') {
							this.form.chongxi = []
							this.detailmsg.flushingEquipment = []
						} else {
							this.form.chongxi = this.detailmsg.flushingEquipment.split(',')
							this.detailmsg.flushingEquipment = this.detailmsg.flushingEquipment.split(
								',')
						}
						//防尘降尘
						if (this.detailmsg.dustControl == null || this.detailmsg.dustControl == '') {
							this.form.fangchen = []
							this.detailmsg.dustControl = []
						} else {
							this.form.fangchen = this.detailmsg.dustControl.split(',')
							this.detailmsg.dustControl = this.detailmsg.dustControl.split(',')
						}
						//视频
						if (this.detailmsg.videoSurveillance == null || this.detailmsg
							.videoSurveillance == '') {
							this.detailmsg.videoSurveillance = []
							this.form.shipin = []
						} else {
							this.form.shipin = this.detailmsg.videoSurveillance.split(',')
							this.detailmsg.videoSurveillance = this.detailmsg.videoSurveillance.split(
								',')
						}
						//地磅
						if (this.detailmsg.weighbridge == null || this.detailmsg.weighbridge == '') {
							this.detailmsg.weighbridge = []
							this.form.dibang = []
						} else {
							this.form.dibang = this.detailmsg.weighbridge.split(',')
							this.detailmsg.weighbridge = this.detailmsg.weighbridge.split(',')
						}
						//其他
						if (this.detailmsg.other == null || this.detailmsg.other == '') {
							this.detailmsg.other = []
							this.form.qita = []
						} else {
							this.form.qita = this.detailmsg.other.split(
								',') //此处对form图片做数据回填--未操作图片也可直接提交到下一流程
							this.detailmsg.other = this.detailmsg.other.split(',')

							console.log(this.detailmsg.other)
						}
						// 图片显示操作
						this.nameList.forEach((item, index) => {
							console.log(this.detailmsg[item.id])
							item.picList = this.detailmsg[item.id]
						})
						this.$store.state.path = 1
						this.$store.state.center = []
						// 四至范围坐标点解析
						if (this.detailmsg.limits) {
							this.$store.state.path = this.detailmsg.limits.split(',')
							this.detailmsg.limits = this.detailmsg.limits.split(',')
							this.polygons = this.initMapData(this.detailmsg.limits)
							console.log(this.polygons, 'this.polygons,this.polygons')
						}
						this.mapArea = this.detailmsg.limitsArea
						if (this.detailmsg.limitsCentre) {
							let pattern= /[`~!@#$^\-&*()=|{}':;'\\\[\]\<>\/?~！@#￥……&*（）——|{}【】'；：""'。，、？\s]/g;
							this.detailmsg.limitsCentre = this.detailmsg.limitsCentre.replace(pattern,"")
							this.$store.state.center = this.detailmsg.limitsCentre.split(',')
							this.center = this.detailmsg.limitsCentre.split(',')
							console.log(this.center, 'this.centerthis.centerthis.centerthis.center')
						}
						this.getorgByNodeId()
					}

					resolve(res)
				}).catch(err => {
					reject(err)
				})
			})
		},
		// 地图四至范围数据处理
		initMapData(path) {
			let outArr = []
			let lngArr = []
			let latArr = []
			let outArray2 = []
			path.forEach((item, index) => {
				item = item.toString()
				let pattern= /[`~!@#$^\-&*()=|{}':;',\\\[\]\<>\/?~！@#￥……&*（）——|{}【】'；：""'。，、？\s]/g;
				item = item.replace(pattern,"")
				
				console.log(item)
				
				item = Number(item)
				if ((index + 1) % 2 == 0) {
					lngArr.push(item)
				} else {
					latArr.push(item)
				}
			})
			lngArr.forEach((item1, index1) => {
				outArr.push([latArr[index1], lngArr[index1]])
			})
			outArr.forEach((item, index) => {
				outArray2.push({
					longitude: item[0],
					latitude: item[1]
				})
			})
			console.log(outArr, outArray2,path, 'outArray')
			let polygons = [{
				// strokeColor: '#ff33ff80',
				strokeColor: "#FF33FF",
				strokeOpacity: 0.5,
				strokeWeight: 6,
				fillColor: '#1791fc80',
				points: outArray2
			}]
			// console.log(polygons, 'this.polygons,this.polygons')
			return polygons
		},
		getdetail() {
			return new Promise((resolve, reject) => {
				getOrderDetail({
					id: this.id
				}).then(res => {
					console.log(res, 'detailList-----------------')
					this.detailList = res
					this.setInfoOrder(this.detailList)
					this.orderType = this.detailList.orderType
					console.log('oreeer', this.orderType)

					this.timeLeft = parseInt(this.detailList.timeLeft / 60)
					if (this.detailList.timeLeft > 3600) {
						this.timeLeft = parseInt(this.timeLeft / 60) + '时' + this.timeLeft % 60 +
							'分'
					} else {
						this.timeLeft = +this.timeLeft % 60 + '分'
					}

					this.buttontype = this.detailList.type
					this.detailList.formValue.forEach(d => {

						this.formarr.push({
							display_name: d.display_name,
							value: d[d.name]
						})
					})

					// console.log(this.orderType, 88)
					// this.getcircul()

					resolve(res)
				}).catch(err => {
					reject(err)
				})
			})
		},
		//工单流记录
		getcircul() {
			getWorkOrderLogs({
				id: this.idd
			}).then(res => {
				console.log('************************', res)
				this.circulList = res
				this.setInfoRecords(this.circulList)
			})
		},
		// 跳转至表单盖章页面pages/webview/finnish
		orderFinishHandle() {
			this.setInfoApprove(this.detailmsg)
			this.setInfoOrder(this.detailList)
			this.setInfoRecords(this.circulList)
			uni.navigateTo({
				url: `/pages/webview/finnish?type=3`
			})
		},
		//预览图片
		previewPic(item) {
			let arr = []
			arr.push(item)
			console.log('图片预览', arr)
			uni.previewImage({
				urls: arr
			})
		},
		//确认审核
		comfirm(flag) {
			if (this.outorder != 0 && !flag) {
				uni.showModal({
					title: '提示',
					content: '是否确定提交审核？',
					confirmText: '确定',
					cancelText: '取消',
					success: res => {
						if (res.confirm) {
							if (this.outorder == 1) {
								postCloseOrder({
									id: this.id,
									other: {
										result: "关闭",
										content: this.type_value
									}
								}).then(d => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: '关闭成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 500)
								}).catch(res => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: res.data.msg,
										type: 'warning',
										url: '/pages/index/approval/index'
									}, 300)
								})
							} else if (this.outorder == 2) {
								postWithdraw({
									id: this.id,
									other: {
										result: "退单整改",
										content: this.type_value
									}
								}).then(res => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: '退单成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 500)
									// uni.navigateBack()
								}).catch(res => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: res.data.msg,
										type: 'warning',
										url: '/pages/index/approval/index'
									}, 300)
								})
							} else {
								postCloseOrder({
									id: this.id,
									other: {
										result: "关闭",
										content: this.type_value
									}
								}).then(d => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: '关闭成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 500)
								})
							}

						}
					}
				});

			} else {
				if (this.buttontype == 2) {
					uni.showModal({
						title: '提示',
						content: '是否确定提交？',
						confirmText: '确定',
						cancelText: '取消',
						success: res => {
							if (res.confirm) {
								postOrderHandle({
									id: this.id,
									other: {
										result: "工单处置",
										content: this.type_value
									}
								}).then(res => {
									// this.getdetail()
									this.show = false
									this.showPass = false
									uni.$emit('updatelist', 10)

									this.$refs.uToast.show({
										title: '审核成功',
										type: 'success',
										url: '/pages/index/approval/index'
									}, 300)
									// uni.navigateBack()
								}).catch(res => {
									uni.$emit('updatelist', 10)
									this.$refs.uToast.show({
										title: res.data.msg,
										type: 'warning',
										url: '/pages/index/approval/index'
									}, 300)
								})
							}
						}
					});
				} else if (this.buttontype == 3) {
					// this.nodeName!='初步方案'
					if (0) {
						this.$refs.uToast.show({
							title: '请上传方案',
							type: 'warning',
						}, 300)
					} else {
						uni.showModal({
							title: '提示',
							content: '是否确定提交审核？',
							confirmText: '确定',
							cancelText: '取消',
							success: res => {
								if (res.confirm) {
									postOrderAudit({
										id: this.id,
										other: {
											result: "工单审核",
											content: this.pass_value
										}
									}).then(res => {
										// this.getdetail()
										
										this.show = false
										this.showPass = false
										// 3 自规局审核需要更新四至范围数据
										if(this.stepsnumber == 3) {
											uni.$emit('updatelist', 10)
											this.updatexiaonamsg() 
											setTimeout(function() {
												uni.navigateBack()  //更新接口有uTost,navigateBack返回
											},800)
										}else{
											uni.$emit('updatelist', 10)
											//重新获取完成任务的recordId
											setTimeout(() => {
												let params = {
													// isDelay: this.isDelay,
													size: 1000,
													itemId: "402887ae7b62cd4f017b62ef1f4c0170"
												}
												getMyList(params).then(res => {
													res.rows.forEach(d => {
														if (d.id == this.idd) {
															this.id = d.recordId
															this.nodeId = d.nodeId
															this.checkop = -1
														}
													})
													this.getcircul()
													console.log('流转记录',this.circulList)
													this.orderFinishHandle()	
												})
											}, 100)
										}
										// this.stepsnumber == 3 ?  : ''
										console.log(res)
									}).catch(res => {
										uni.$emit('updatelist', 10)
										this.$refs.uToast.show({
											title: '提交成功！',
											type: 'warning',
											url: '/pages/index/approval/index'
										}, 300)
									})
								}
							}
						});
					}

				}
			}


		},
		//任务认领
		taketask() {
			uni.showModal({
				title: '提示',
				content: '是否确定认领？',
				confirmText: '确定',
				cancelText: '取消',
				success: res => {
					if (res.confirm) {
						getTakeTask({
							id: this.id
						}).then(res => {
							this.orderType = 1
							// buttontype 1现场踏勘，3渣土办，自规局 11部门
							this.xiaonaEdit = (this.buttontype == 1 ? 1 : -1)
							this.xiaonaEdit2 = (this.stepsnumber == 3 ? 1 : -1) //渣土办审核需要地图可编辑
							console.log(res)
						}).catch(res => {
							console.log(res)
			
							uni.$emit('updatelist', 10)
							this.$refs.uToast.show({
								title: '认领成功！',
								type: 'warning',
								url: '/pages/index/approval/index'
							}, 300)
						})
					}
				}
			})
		},
		// 选中某个复选框时，由checkbox时触发
		checkboxChange(e) {
			console.log(e);
			let index = this.activelist.indexOf(e.name[0])
			let num = this.activeOrgName.indexOf(e.name[1])
			if (index > -1) {
				this.activelist.splice(index, 1)
			} else {
				this.activelist.push(e.name[0])
			}
			if (num > -1) {
				this.activeOrgName.splice(num, 1)
			} else {
				this.activeOrgName.push(e.name[1])
			}
			console.log(this.activeOrgName,this.activelist);
		},
		// 全选
		checkedAll() {
			this.list.map(val => {
				val.checked = true;
			})
		},
		//退单
		passout(index) {
			this.show = true
			this.outorder = index
		},
		comfirm_part() {
			uni.showModal({
				title: '提示',
				content: '是否确定提交？',
				confirmText: '确定',
				cancelText: '取消',
				success: res => {
					if (res.confirm) {
						if (this.buttontype == 11) {
							allocatedo({
								"id": this.id,
								"formValue": [{
									"name": "orderName",
									"type": "text",
									"params": {},
									"display_name": "分派处置内容",
									"orderName": '审核通过'
								}],
								other: {
									result: "部门审核通过",
									content: this.pass_value
								}
							}).then(d => {
								console.log(d)

								this.show = false
								uni.$emit('updatelist', 10)
								this.$refs.uToast.show({
									title: '提交成功',
									type: 'success',
									url: '/pages/index/approval/index'
								}, 500)
								// uni.navigateBack()
							}).catch(res => {
								uni.$emit('updatelist', 10)
								console.log(res)
								this.$refs.uToast.show({
									title: res.data.msg,
									type: 'warning',
									url: '/pages/index/approval/index'
								}, 300)
							})
						} else {
							// this.activelist = ['GO_df2f46315d414518a31bea909fbd67a6']
						if(this.activelist.length==0){
								this.$refs.uToast.show({
									title: '请选择的分派部门',
									type: 'warning'
								}, 500)
						}else{
							allocate({
								id: this.id,
								// orgIds: this.activelist.join(','),
								orgIds: this.activelist,
								other: {
									result: "工单分配",
									content: "工单分配",
									orgName:this.activeOrgName
								}
							}).then(res => {
								this.show = false
								this.showPass = false
								uni.$emit('updatelist', 10)
								// uni.navigateBack()
								this.$refs.uToast.show({
									title: '提交成功',
									type: 'success',
									url: '/pages/index/approval/index'
								}, 300)

								console.log(res)
							}).catch(res => {
								uni.$emit('updatelist', 10)
								this.$refs.uToast.show({
									title: res.data.msg,
									type: 'warning',
									url: '/pages/index/approval/index'
								}, 300)
							})
							}
						}
					}
				}
			});

			console.log(this.activelist)
		},
		getDate(type) {
			const date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();

			if (type === 'start') {
				year = year - 60;
			} else if (type === 'end') {
				year = year + 2;
			}
			month = month > 9 ? month : '0' + month;;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		},
		navigationToEvent() {
			console.log(this.detailmsg.limit, 'this.detailList.limit')
			console.log('this.checkop', this.checkop)
			if (this.stepsnumber == 1) { //现场踏勘
				if (this.$store.state.path == 1) { //未绘制
					uni.navigateTo({
						url: `/pages/drawmap/index?&lat=${this.detailmsg.latitude}&lng=${this.detailmsg.longitude}`
					})
				} else {
					uni.navigateTo({
						url: `/pages/drawmap/index?&lat=${this.detailmsg.latitude}&lng=${this.detailmsg.longitude}&fourArea=${this.$store.state.path.toString()}`
					})
				}

			} else if (this.stepsnumber == 3) { //自规局审核
				if (this.$store.state.path == 1) { //未手动绘制
					if (this.detailmsg.limits) { //踏勘阶段已经绘制
						uni.navigateTo({
							url: `/pages/drawmap/index?&lat=${this.detailmsg.latitude}&lng=${this.detailmsg.longitude}&fourArea=${this.detailmsg.limits}`
						})
					} else {
						uni.navigateTo({
							url: `/pages/drawmap/index?&lat=${this.detailmsg.latitude}&lng=${this.detailmsg.longitude}`
						})
					}

				} else {
					uni.navigateTo({
						url: `/pages/drawmap/index?&lat=${this.detailmsg.latitude}&lng=${this.detailmsg.longitude}&fourArea=${this.$store.state.path.toString()}`
					})
				}
			} else {
				// uni.navigateTo({
				// 	url: `/pages/drawmap/index?&lat=${this.detailmsg.longitude}&lng=${this.detailmsg.longitude}&fourArea=${this.detailmsg.limits}&type=check`
				// })
			}
		},
		//返回上一级
		goBack() {
			uni.navigateBack()
		},
		//获取当前位置
		getLocation() {
			uni.getLocation({
				type: 'wgs84',
				geocode: true,
				success: res => {
					console.log(res, 888)
					this.form.lat = res.latitude
					this.form.lng = res.longitude
					this.getaddress(this.form.lng, this.form.lat)
				}
			});
		},

		//重新定位
		rePostioning() {
			// this.addressModalshow = true
			uni.showLoading({
				title: '正在获取当前位置'
			});
			setTimeout(() => {
				this.getLocation()
			}, 800)
		},

		getaddress(lat, lon) {
			this.test.getRegeo({
				location: lat + ',' + lon, //location的格式为'经度,纬度'
				//成功回调
				success: (data) => {
					console.log(data[0].regeocodeData.formatted_address, data[0].name)
					this.form.address = data[0].regeocodeData.formatted_address
				},
				fail: function(info) {
					//失败回调
					console.log(info)
				}
			})
		},

		inputs(e) {
			let val = 0
			// this.detailmsg.muckEarthQuantity1 = e.detail.value.replace(/\D/g, '')
			// this.$refs['inputest'].value = this.detailmsg.muckEarthQuantity1
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.muckEarthQuantity1) < parseInt(this.detailmsg.muckEarthQuantity2)) {
				this.redshow1 = true
			} else {
				this.redshow1 = false
			}
			console.log(this.detailmsg.muckEarthQuantity1, this.detailmsg.allEarthQuantity1)
		},
		input_year(e) {
			let val = 0
			this.detailmsg.muckEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			if (parseInt(this.detailmsg.muckEarthQuantity1) < parseInt(this.detailmsg.muckEarthQuantity2)) {
				this.redshow1 = true
			} else {
				this.redshow1 = false
			}
		},
		inputs1(e) {
			let val = 0
			this.detailmsg.loessEarthQuantity1 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.loessEarthQuantity1) < parseInt(this.detailmsg.loessEarthQuantity2)) {
				this.redshow2 = true
			} else {
				this.redshow2 = false
			}
		},
		input_year1(e) {
			let val = 0
			this.detailmsg.loessEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			if (parseInt(this.detailmsg.loessEarthQuantity1) < parseInt(this.detailmsg.loessEarthQuantity2)) {
				this.redshow2 = true
			} else {
				this.redshow2 = false
			}
			console.log(this.detailmsg.muckEarthQuantity2, this.detailmsg.allEarthQuantity2)
		},
		inputs2(e) {
			let val = 0
			this.detailmsg.plantingSoilEarthQuantity1 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.plantingSoilEarthQuantity1) < parseInt(this.detailmsg
					.plantingSoilEarthQuantity2)) {
				this.redshow3 = true
			} else {
				this.redshow3 = false
			}
		},
		input_year2(e) {
			let val = 0
			this.detailmsg.plantingSoilEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			if (parseInt(this.detailmsg.plantingSoilEarthQuantity1) < parseInt(this.detailmsg
					.plantingSoilEarthQuantity2)) {
				this.redshow3 = true
			} else {
				this.redshow3 = false
			}
			console.log(this.detailmsg.muckEarthQuantity2, this.detailmsg.allEarthQuantity2)
		},
		inputs5(e) {
			let val = 0
			this.detailmsg.otherEarthQuantity1 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.otherEarthQuantity1) < parseInt(this.detailmsg.otherEarthQuantity2)) {
				this.redshow6 = true
			} else {
				this.redshow6 = false
			}
		},
		input_year5(e) {
			let val = 0
			this.detailmsg.otherEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			if (parseInt(this.detailmsg.otherEarthQuantity1) < parseInt(this.detailmsg.otherEarthQuantity2)) {
				this.redshow6 = true
			} else {
				this.redshow6 = false
			}
			console.log(this.detailmsg.muckEarthQuantity2, this.detailmsg.allEarthQuantity2)
		},
		inputs7(e) {
			let val = 0
			this.detailmsg.dangEarthQuantity1 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.dangEarthQuantity1) < parseInt(this.detailmsg.dangEarthQuantity2)) {
				this.redshow7 = true
			} else {
				this.redshow7 = false
			}
		},
		input_year7(e) {
			let val = 0
			this.detailmsg.dangEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			if (parseInt(this.detailmsg.dangEarthQuantity1) < parseInt(this.detailmsg.dangEarthQuantity2)) {
				this.redshow7 = true
			} else {
				this.redshow7 = false
			}
			console.log(this.detailmsg.muckEarthQuantity2, this.detailmsg.allEarthQuantity2)
		},
		inputs3(e) {
			let val = 0
			this.detailmsg.slurryEarthQuantity1 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.slurryEarthQuantity1) < parseInt(this.detailmsg.slurryEarthQuantity2)) {
				this.redshow4 = true
			} else {
				this.redshow4 = false
			}
		},
		input_year3(e) {
			let val = 0
			this.detailmsg.slurryEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			console.log(this.detailmsg.muckEarthQuantity2, this.detailmsg.allEarthQuantity2)
			if (parseInt(this.detailmsg.slurryEarthQuantity1) < parseInt(this.detailmsg.slurryEarthQuantity2)) {
				this.redshow4 = true
			} else {
				this.redshow4 = false
			}
		},
		inputs4(e) {
			let val = 0
			this.detailmsg.wasterEarthQuantity1 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity1) + parseInt(this.detailmsg.loessEarthQuantity1) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity1) +
				parseInt(this.detailmsg.slurryEarthQuantity1) + parseInt(this.detailmsg.wasterEarthQuantity1) +
				parseInt(this.detailmsg.otherEarthQuantity1) + parseInt(this.detailmsg.dangEarthQuantity1)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity1': val
			})
			if (parseInt(this.detailmsg.wasterEarthQuantity1) < parseInt(this.detailmsg.wasterEarthQuantity2)) {
				this.redshow5 = true
			} else {
				this.redshow5 = false
			}
		},
		input_year4(e) {
			let val = 0
			this.detailmsg.wasterEarthQuantity2 = e.detail.value
			val = parseInt(this.detailmsg.muckEarthQuantity2) + parseInt(this.detailmsg.loessEarthQuantity2) + parseInt(
					this.detailmsg.plantingSoilEarthQuantity2) +
				parseInt(this.detailmsg.slurryEarthQuantity2) + parseInt(this.detailmsg.wasterEarthQuantity2) +
				parseInt(this.detailmsg.otherEarthQuantity2) + parseInt(this.detailmsg.dangEarthQuantity2)
			this.detailmsg = Object.assign({}, this.detailmsg, {
				'allEarthQuantity2': val
			})
			if (parseInt(this.detailmsg.wasterEarthQuantity1) < parseInt(this.detailmsg.wasterEarthQuantity2)) {
				this.redshow5 = true
			} else {
				this.redshow5 = false
			}
			console.log(this.detailmsg.muckEarthQuantity2, this.detailmsg.allEarthQuantity2)
		},
		inputsName(e) {
			let val = 0
			this.detailmsg.fieldName = e.detail.value
		}
	}
}
